#ifdef HAVE_CONFIG_H
# include <blob/config.h>
#endif
#include <blob/arch.h>


#define  XTAL	14745600

static int change_speed(int baud) {
	int divisor = XTAL /(baud<<4);

	FFLCR |= LCR_DLAB;

	FFDLL = (divisor & 0xFF);
	FFDLH = (divisor >> 8);

	FFLCR &= ~LCR_DLAB;

	return 0;
}

void putc(char c) {
	while (0==(FFLSR & LSR_TDRQ)) ;
	FFTHR = c;
}

void puts(char *s) {

	char *p=s;

	while(*p) {
		putc(*p);
		p++;
	}
}

void init_uart(int baud) {
	CKEN |= CKEN6_FFUART;
	FFLCR = 0x3;
	FFMCR = MCR_DTR | MCR_RTS ;
	FFFCR = 0;
	FFIER = IER_UUE;

	change_speed(baud);
}
